package com.wn.icloud.domain;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonManagedReference;

import javax.persistence.*;
import java.util.List;

/**
 * @author liguangcai
 * @date 2018/11/30 15:45
 */
@SuppressWarnings({ "serial", "rawtypes" })
@MappedSuperclass
public class BaseTreeEntityDomain<T extends BaseTreeEntityDomain> extends BaseEntityDomain {

	@JsonManagedReference("parent-children")
	@OneToMany(mappedBy="parent",cascade = CascadeType.REMOVE,fetch= FetchType.EAGER)
	List<T> children;

	@Transient
	boolean leaf = true;

	@JsonBackReference("parent-children")
	@ManyToOne
	@JoinColumn(name="parent_id")
	T parent;

	@Column
	String text;

	public List<T> getChildren() {
		return children;
	}

	public void setChildren(List<T> children) {
		this.children = children;
	}

	public boolean isLeaf() {
		return leaf;
	}

	public void setLeaf(boolean leaf) {
		this.leaf = leaf;
	}

	public T getParent() {
		return parent;
	}

	public void setParent(T parent) {
		this.parent = parent;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}



}
